﻿/// <reference path="jquery-1.2.5-intellisense.js" />
/* 浮动层显示 */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
/* 选项卡切换 */
function go_to(numTarget, numCount, strTagName, strBlockName)
{
	for(var i=1;i<=numCount;i++)
	{
		if(numTarget == i)
		{
			document.getElementById(strTagName + i).className="selected";
			document.getElementById(strBlockName + i).style.display="";
		}
		else
		 {
			document.getElementById(strTagName + i).className="";
			document.getElementById(strBlockName + i).style.display="none";
		}
	}
}
/* 加入收藏夹 */
function JSAddFavorite(FavName, FavUrl)
{
    if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
    {
        //  firefox
        window.sidebar.addPanel( FavName, FavUrl, '' );
    }
    else if ( document.all && "object" == typeof( window.external ) )
    {
        //  ie
        window.external.AddFavorite(FavUrl, FavName);
    }
}

//关闭窗口
function CloseWin()
{
    var ua=navigator.userAgent;
    var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
    if(ie)
    {
        var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
        if(IEversion< 5.5)
        {
            var str  = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
            str += '<param name="Command" value="Close"></object>';
            document.body.insertAdjacentHTML("beforeEnd", str);
            document.all.noTipClose.Click();
        }
        else
        {
            window.opener =null;
            window.close();
        }
    }
    else
    {
        window.close()
    }
}

//转动新闻
function srcMarquee(){
	this.ID = document.getElementById(arguments[0]);
	if(!this.ID){this.ID = -1;return;}
	this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
	this.Step = 1;
	this.Timer = 30;
	this.DirectionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};
	this.Direction = arguments[1];
	this.Step = arguments[2];
	this.Width = arguments[3];
	this.Height = arguments[4];
	this.Timer = arguments[5];
	this.DelayTime = arguments[6];
	this.WaitTime = arguments[7];
	this.ScrollStep = arguments[8]
	this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
	this.ID.noWrap = true;
	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	this.Start();
}
srcMarquee.prototype.Start = function(){
	if(this.ID == -1)return;
	if(this.WaitTime < 800)this.WaitTime = 800;
	if(this.Timer < 20)this.Timer = 20;
	if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
	if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
	if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
	this.HalfWidth = Math.round(this.Width / 2);
	this.BakStep = this.Step;
	this.ID.style.width = this.Width;
	this.ID.style.height = this.Height;
	if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
	var msobj = this;
	var timer = this.Timer;
	var delaytime = this.DelayTime;
	var waittime = this.WaitTime;
	msobj.StartID = function(){msobj.Scroll()}
	msobj.Continue = function(){
		if(msobj.MouseOver == 1){
		setTimeout(msobj.Continue,delaytime);
     }
     else{ clearInterval(msobj.TimerID);
		msobj.CTL = msobj.Stop = 0;
		msobj.TimerID = setInterval(msobj.StartID,timer);
     }
    }
	msobj.Pause = function(){
		msobj.Stop = 1;
		clearInterval(msobj.TimerID);
		setTimeout(msobj.Continue,delaytime);
    }
	msobj.Begin = function(){
   msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
   if((msobj.Direction <= 1 && msobj.ClientScroll <msobj.Height) || (msobj.Direction > 1 && msobj.ClientScroll <msobj.Width))return;
   msobj.ID.innerHTML += msobj.ID.innerHTML;
   msobj.TimerID = setInterval(msobj.StartID,timer);
   if(msobj.ScrollStep < 0)return;
   msobj.ID.onmousemove = function(event){
       if(msobj.ScrollStep == 0 && msobj.Direction > 1){
			var event = event || window.event;
			if(window.event){
				if(msobj.IsNotOpera){msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;}
				else{msobj.ScrollStep = null;return;}
			}
			else{msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;}
			msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
			msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
			msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
			}
		}
		msobj.ID.onmouseover = function(){
			if(msobj.ScrollStep == 0)return;
			msobj.MouseOver = 1;
			clearInterval(msobj.TimerID);
		}
		msobj.ID.onmouseout = function(){
		if(msobj.ScrollStep == 0){
			if(msobj.Step == 0)msobj.Step = 1;
			return;
		}
		msobj.MouseOver = 0;
		if(msobj.Stop == 0){
			clearInterval(msobj.TimerID);
			msobj.TimerID = setInterval(msobj.StartID,timer);
		}}}
		setTimeout(msobj.Begin,waittime);
}

srcMarquee.prototype.Scroll = function(){
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollTop >= this.ClientScroll){this.ID.scrollTop -= this.ClientScroll;}
		this.ID.scrollTop += this.Step;
	}
} 
//格式化图片大小
function imgresize(o)
{
    if(o.width > document.body.clientWidth - 70)
    {
	    o.style.width=document.body.clientWidth - 70;
    }
}
function csshack()
{
      try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}
}
csshack();


function convertCurrency(currencyDigits) {
    // Constants: 
    var MAXIMUM_NUMBER = 99999999999.99;
    // Predefine the radix characters and currency symbols for output: 
    var CN_ZERO = "零";
    var CN_ONE = "壹";
    var CN_TWO = "贰";
    var CN_THREE = "叁";
    var CN_FOUR = "肆";
    var CN_FIVE = "伍";
    var CN_SIX = "陆";
    var CN_SEVEN = "柒";
    var CN_EIGHT = "捌";
    var CN_NINE = "玖";
    var CN_TEN = "拾";
    var CN_HUNDRED = "佰";
    var CN_THOUSAND = "仟";
    var CN_TEN_THOUSAND = "万";
    var CN_HUNDRED_MILLION = "亿";
    var CN_SYMBOL = "人民币：";
    var CN_DOLLAR = "元";
    var CN_TEN_CENT = "角";
    var CN_CENT = "分";
    var CN_INTEGER = " 整";

    // Variables: 
    var integral;    // Represent integral part of digit number. 
    var decimal;    // Represent decimal part of digit number. 
    var outputCharacters;    // The output result. 
    var parts;
    var digits, radices, bigRadices, decimals;
    var zeroCount;
    var i, p, d;
    var quotient, modulus;

    // Validate input string: 
    currencyDigits = currencyDigits.toString();
    if (currencyDigits == "") {
        //alert("Empty input!");
        return "";
    }
    if (currencyDigits.match(/[^,.\d]/) != null) {
        return "输入的数字不正确";
    }
    if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
        return "输入的数字不正确";
    }

    // Normalize the format of input digits: 
    currencyDigits = currencyDigits.replace(/,/g, "");    // Remove comma delimiters. 
    currencyDigits = currencyDigits.replace(/^0+/, "");    // Trim zeros at the beginning. 
    // Assert the number is not greater than the maximum number. 
    if (Number(currencyDigits) > MAXIMUM_NUMBER) {
        alert("Too large a number to convert!");
        return "";
    }

    // Process the coversion from currency digits to characters: 
    // Separate integral and decimal parts before processing coversion: 
    parts = currencyDigits.split(".");
    if (parts.length > 1) {
        integral = parts[0];
        decimal = parts[1];
        // Cut down redundant decimal digits that are after the second. 
        decimal = decimal.substr(0, 2);
    }
    else {
        integral = parts[0];
        decimal = "";
    }
    // Prepare the characters corresponding to the digits: 
    digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
    radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
    bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
    decimals = new Array(CN_TEN_CENT, CN_CENT);
    // Start processing: 
    outputCharacters = "";
    // Process integral part if it is larger than 0: 
    if (Number(integral) > 0) {
        zeroCount = 0;
        for (i = 0; i < integral.length; i++) {
            p = integral.length - i - 1;
            d = integral.substr(i, 1);
            quotient = p / 4;
            modulus = p % 4;
            if (d == "0") {
                zeroCount++;
            }
            else {
                if (zeroCount > 0) {
                    outputCharacters += digits[0];
                }
                zeroCount = 0;
                outputCharacters += digits[Number(d)] + radices[modulus];
            }
            if (modulus == 0 && zeroCount < 4) {
                outputCharacters += bigRadices[quotient];
            }
        }
        outputCharacters += CN_DOLLAR;
    }
    // Process decimal part if there is: 
    if (decimal != "") {
        for (i = 0; i < decimal.length; i++) {
            d = decimal.substr(i, 1);
            if (d != "0") {
                outputCharacters += digits[Number(d)] + decimals[i];
            }
        }
    }
    // Confirm and return the final output string: 
    if (outputCharacters == "") {
        outputCharacters = CN_ZERO + CN_DOLLAR;
    }
    if (decimal == "") {
        outputCharacters += CN_INTEGER;
    }
    outputCharacters = CN_SYMBOL + outputCharacters;
    return outputCharacters;
}

function GetDateNow() {
    var d = new Date();
    return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
}


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
    var sCookie = sName + '=' + encodeURIComponent(sValue);
    if (oExpires) {        
        if (Number(oExpires)) {
           var  date = new Date();
           date.setTime(date.getTime() + (oExpires * 12  * 60 * 1000));
        } else {
        date = oExpires;
        }
        sCookie += '; expires=' + date.toGMTString();
    }
    if (sPath) {
        sCookie += '; path=' + sPath;
    }
    if (sDomain) {
        sCookie += '; domain=' + sDomain;
    }
    if (bSecure) {
        sCookie += ';secure';
    }
    document.cookie = sCookie;
}

function getCookie(sName) {
    var sRE = "(?:;.)?" + sName + "=([^;]*);?";
    var oRE = new RegExp(sRE);
    if (oRE.test(document.cookie)) {
        return decodeURIComponent(RegExp["$1"]);
    } else {
        return null;
    }
}
//只能輸入數字
function onlyNum() { if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode == 190) || (event.keyCode == 110) || (event.keyCode == 8) || (event.keyCode == 9) || (event.keyCode == 46))) event.returnValue = false; }

//时间倒数
//parentID = "#TeamTime"
//<span id="TeamTime"><em>20</em>天<em>7</em>小时<em>3</em>分<em>2</em>秒</span>
function getLeaveTime(parentID) {
    $.each(parentID, function(i, n) {
        getLeavaSingleTime(n); 
        //alert(n);
    });
    return;
}

function getLeavaSingleTime(parentID) {

    var tid = parentID + ">em";

    if ($(tid).text()=='') {
        return;
    }
    else {
        var sec = $(tid).eq(3).text();
        var min = $(tid).eq(2).text();
        var hou = $(tid).eq(1).text();
        var day = $(tid).eq(0).text();
        if (Number(sec) > 0)
            $(tid).eq(3).text(--sec);
        else {
            $(tid).eq(3).text(59);
            if (Number(min) > 0)
                $(tid).eq(2).text(--min);
            else {
                $(tid).eq(2).text(59);
                if (Number(hou) > 0)
                    $(tid).eq(1).text(--hou);
                else {
                    $(tid).eq(1).text(23);
                    if (Number(day) > 0)
                        $(tid).eq(0).text(--day);
                    else {
                        $(parentID).text("已结束");
                        //clearInterval(time);
                    }
                }
            }
        }
    }

}

function calculateCountdown() {
    //The current date and time 
    var todaysDate = new Date();

    /*The date and time of the target date in Greenwich Mean Time (year, month-1, day of month, hours in 24-hour notation, minutes, seconds, milliseconds). The "month-1" can trip you up if you're not carefully. So, for example, May is 4.*/
    var targetDate = new Date(2008, 10, 25, 13, 0, 0, 0);
    //var str = "2008/10/22 09:21:00";
    /*The getTimezoneOffset function returns the number of minutes west of GMT the browser is. For example, a browser in the New York EST timezone would be 300 minutes off of GMT. NOTE: does not factor in Daylight Saving Time.*/
    var timezoneOffset = (todaysDate.getTimezoneOffset() * 60) * 1000;

    /*Factor in the time zone of the web browser before determine the time between now and the conference start time.*/
    var timeDifference = (targetDate - timezoneOffset) - todaysDate;

    //Now calculate the days, hours, minutes, and seconds from the time difference 
    var countDown = new Array(4);
    countDown[0] = Math.floor((((timeDifference / 1000) / 60) / 60) / 24);
    countDown[1] = Math.floor((((timeDifference / 1000) / 60) / 60) % 24);
    countDown[2] = Math.floor(((timeDifference / 1000) / 60) % 60);
    countDown[3] = Math.floor((timeDifference / 1000) % 60);

    //Output the result
    return countDown;
} //end of the calculateCountdown function


function checkallBox(form, checkall, source) {

    var flag =true;
    if (document.getElementById(checkall).value == '全选') 
    {  flag=true;
        document.getElementById(checkall).value = '反选';
     }
     else if(document.getElementById(checkall).value == '反选') 
     {flag=false;
                document.getElementById(checkall).value = '全选';
    }
    if (source)
        flag = source;
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if (e.type == "checkbox") {
                e.checked = flag;
            }
            
        }
    }

function checkSelect(form,message) {   
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if (e.type == "checkbox" && e.checked) {
            return true;
        }
    }
    alert(message);
    return false;
}
function SetparseQuery(query) {
    query = query.replace(/^[^\?]+\??/, '');
    //alert(query);
    query = decodeURIComponent(query);
    query = query.replace(/[\$]/g, '_');
    //alert(query);
    var Params = {};
    if (!query) { return Params; } // return empty object
    var Pairs = query.split(/[;&]/);
    for (var i = 0; i < Pairs.length; i++) {
        var KeyVal = Pairs[i].split('=');
        if (!KeyVal || KeyVal.length != 2) { continue; }
        var key = unescape(KeyVal[0]);
        var val = unescape(KeyVal[1]);
        val = val.replace(/\+/g, ' ');
        try{
        $('#' + key).val(val);
        }catch(e){continue;}
       // Params[key] = val;
    }
   // return Params;
}



function UrlDecode(str){
  var ret="";
  for(var i=0;i<str.length;i++){
   var chr = str.charAt(i);
    if(chr == "+"){
      ret+=" ";
    }else if(chr=="%"){
     var asc = str.substring(i+1,i+3);
     if(parseInt("0x"+asc)>0x7f){
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
      i+=5;
     }else{
      ret+=asc2str(parseInt("0x"+asc));
      i+=2;
     }
    }else{
      ret+= chr;
    }
  }
  return ret;
}